import { defineStore } from 'pinia'
import { ref } from 'vue';
export const useMessageStore = defineStore('message',
    () => {
        const unread = ref([
            {
                date: "2023-04-19 20:00:00",
                title: "【系统通知】该系统将于今晚凌晨2点到5点进行升级维护与数据更新",
            },
            {
                date: "2023-19 21:00:00",
                title: "恭喜你获得2024NBA全明星票王",
            },
        ]);
        const read = ref([
            {
                date: "2023-19 20:00:00",
                title: "恭喜你获得NBA季中赛总冠军与FMVP的荣誉",
            },
        ]);
        const recycle = ref([
            {
                date: "2023-19 20:00:00",
                title: "【系统通知】您的轮休申请已经批准",
            },
        ]);

        const handleRead = (index) => {
            if (index || index === 0) {
                const item = unread.value.splice(index, 1);
                read.value = item.concat(read.value);
            } else {
                read.value = unread.value.concat(read.value);
                unread.value = []
               
            }

        }
        const handleRestore = (index) => {
            if (index || index === 0) {
                const item = recycle.value.splice(index, 1);
                read.value = item.concat(read.value);
            } else {
                recycle.value = []
            }

        }
        const handleDel = (index) => {
            if (index || index === 0) {
                const item = read.value.splice(index, 1);
                recycle.value = item.concat(recycle.value);
            } else {
                recycle.value = read.value.concat(recycle.value)
                read.value = []
            }

        }
        return {
            unread,
            read,
            recycle,
            handleRead,
            handleRestore,
            handleDel
        }

    }
)